<template>
  <div>
    <input
      type="text"
      placeholder="请输入要搜索的关键字"
      v-if="flag"
      @click="click"
      ref="ipt"
    />
    <button v-else @click="click">点击搜索</button>
  </div>
</template>

<script>
// dom.focus() 获取焦点
export default {
  mounted() {},
  data() {
    return {
      flag: false,
    }
  },
  methods: {
    click(){
      this.flag=!this.flag
      this.flag&&this.$nextTick(()=>this.$refs.ipt.focus())
    }
  },
}
</script>

<style></style>
